package test.manager;

import icom.acm.util.DBConnect;

import java.sql.Statement;

import test.bean.T_TEST;

import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;

public class T_TestMgr {
	public int insert(T_TEST t){
		int flag = -1;
		String sql = "INSERT INTO T_TEST(T_ID, T_NEXTID, T_BLOB)" +
				" VALUES(NULL, ?, ?)";
		DBConnect db = new DBConnect();
		db.setAutoCommit(false);
		
		db.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);		
		db.setInt(1, t.getT_NEXTID());
	//	db.setBlob(2, t.getT_BLOB(), 3);
		try {
			db.excute();
			flag = db.getGeneratedKeys();
			db.commit();
			
		} catch (MySQLIntegrityConstraintViolationException e) {
			// 数据重复
			flag = -1;
		} finally{
			db.setAutoCommit(true);
			db.close();
		}
		return flag;
	}
}
